package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.entity.NursingPlan;
import com.zzyl.entity.NursingProjectPlan;
import com.zzyl.service.NursingService;
import com.zzyl.vo.NursingPlanVo;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: Learner
 * @Version: 1.0
 * 护理计划
 */
@RestController
@RequestMapping("/nursing/plan")
@Api(tags = "护理计划")
public class NursingController extends BaseController {
    @Autowired
    private NursingService nursingService;

    @ApiOperation("查询所有护理计划")
    @GetMapping
    private ResponseResult<List<NursingPlan>> getPlan() {
        List<NursingPlan> nursingPlan = nursingService.getPlan();
        return success(nursingPlan);
    }

    @PostMapping
    @ApiOperation("新增护理计划")
    public ResponseResult addNursing(@RequestBody NursingPlanDto nursingPlanDto) {
        nursingService.addNursing(nursingPlanDto);
        return success();
    }


    @GetMapping("/search")
    @ApiOperation("分页条件查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "护理项目名称", dataType = "String"),
            @ApiImplicitParam(name = "pageNum", value = "当前页码", dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页显示条数", dataType = "Integer"),
            @ApiImplicitParam(name = "status", value = "状态", dataType = "Integer")
    })
    public ResponseResult<PageResponse<NursingPlan>> getSearch(
            @RequestParam(name = "name", required = false) String planName,
            Integer status,
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize

    ) {
        PageResponse<NursingPlan> nursingPlan = nursingService.getSearch(planName, status, pageNum, pageSize);
        return success(nursingPlan);
    }

    @ApiOperation("根据ID查询")
    @GetMapping("/{id}")
    public ResponseResult getById(@ApiParam("护理计划ID") @PathVariable long id) {
        NursingPlanVo nursingPlanvo = nursingService.getById(id);
        return success(nursingPlanvo);
    }

    @PutMapping
    @ApiOperation("修改护理计划")
    public ResponseResult updateById(@RequestBody NursingPlanDto nursingPlanDto){
        nursingService.updateById(nursingPlanDto);
        return success();
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除护理计划")
    public ResponseResult delById(@ApiParam("护理计划ID") @PathVariable long id){
        nursingService.delById(id);
        return success();
    }

    @PutMapping("/{id}/status/{status}")
    @ApiOperation("启用禁用状态管理")
    public ResponseResult updateStatus(@ApiParam("护理等级id") @PathVariable long id,
                                       @ApiParam("状态") @PathVariable Integer status){
        nursingService.updateStatus(id,status);
        return success();
    }

}
